package com.palm.hubo2o.ui.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.palm.hubo2o.R;
import com.palm.hubo2o.event.BetEvent;
import com.palm.hubo2o.model.Bet;
import com.palm.hubo2o.util.EnumCode;
import com.palm.palmutils.MathUtils;
import com.palm.palmutils.widget.EasyRecyclerView;

import de.greenrobot.event.EventBus;


/**
 * Created by dest1 on 2015/10/15.
 */
public class D3Z6Fragment extends MostLotteryFragment {
    private final Bet bet = new Bet(EnumCode.gameId.D3);

    @Override
    public void onCreateView2(View view, Bundle savedInstanceState) {
        super.onCreateView2(view, savedInstanceState);
        setupBalls(null, 0, 10);
        bet.setPlayType(EnumCode.PlayType.D3_Z6);
    }

    @Override
    public boolean onRandomBalls() {
        onClearChoices();
        int[] random = MathUtils.randomIn(10, 3);
        for (int aRandom : random) {
            mGrid.setItemChecked(getAdapter().transToRawPosition(aRandom, 0), true);
        }
        return true;
    }


    @Override
    protected void onClearChoices() {
        super.onClearChoices();
        bet.getReds().clear();
    }


    @Override
    protected void onSetMarkText(View parent, int groupIndex) {
        TextView title = (TextView) parent.findViewById(R.id.title_mark);
        TextView tip = (TextView) parent.findViewById(R.id.tip_mark);
        title.setText("选号");
        tip.setText("至少选择3个球");
    }

    @Override
    protected int onSetGroupColor(int groupIndex) {
        return red;
    }

    @Override
    protected boolean onBallChecked(EasyRecyclerView parent, boolean checked, int position, String ballText, int index) {
        if (checked) {
            bet.getReds().add(ballText);
        } else {
            bet.getReds().remove(ballText);
        }
        if (bet.getReds().size() >= 3) {
            bet.setWagerCount((int) (MathUtils.recursive(bet.getReds().size(), 3) / MathUtils.recursive(3)));//Cn3
            EventBus.getDefault().post(new BetEvent(bet));
        } else {
            EventBus.getDefault().post(new BetEvent());
        }
        return true;
    }


}
